package com.weiyuwqj.admin.controller.admin.sys;

import com.weiyuwqj.api.service.SysNoticeService;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.constant.Message;
import com.weiyuwqj.api.model.SysNotice;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * The function of saving, modifying and deleting the site module
 *
 * Copyright 2015-2019 Yunfucloud technology co., Ltd.
 * Created by zhangxiaojian on 15/10/13.
 */
@Controller
@RequestMapping(value = "/admin/sysNnotice")
public class SysNoticeController {

    @Autowired
    SysNoticeService sysNoticeService;

    @ResponseBody
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    public  Object list(@ModelAttribute Paginator p, HttpServletRequest request){
        String userId = request.getParameter("userId");
        String typee = request.getParameter("typee");
        String beginDateTime = request.getParameter("beginDateTime");
        String endDateTime = request.getParameter("endDateTime");
        String orderName= request.getParameter("orderName");
        String orderWay = request.getParameter("orderWay");
        Map<String,Object> map=new HashMap<String,Object>();
        if(StringUtils.isNotEmpty(userId)){
            map.put("userId", userId);
        }
        if(StringUtils.isNotEmpty(typee)){
            map.put("typee", typee);
        }
        if(StringUtils.isNotEmpty(beginDateTime)){
            map.put("beginDateTime", beginDateTime);
        }
        if(StringUtils.isNotEmpty(endDateTime)){
            map.put("endDateTime", endDateTime);
        }
        if(StringUtils.isNotEmpty(orderName)){
            map.put("orderName", orderName);
        }
        if(StringUtils.isNotEmpty(orderWay)){
            map.put("orderWay", orderWay);
        }
        return sysNoticeService.getList(p, map);
    }

    @ResponseBody
    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public  Object add(String contents,
                        String mobile,
                        String title){

        SysNotice sysNotice = new SysNotice();
        sysNotice.setUserId(0);
        sysNotice.setContents(contents);
        sysNotice.setReceiveId(mobile);
        sysNotice.setTitle(title);
        sysNotice.setTypee(1);
        sysNoticeService.save(sysNotice);
        return Message.OK;
    }

}
